export const getRule = ({ ruletype, label }) => {
  const rules = {
    Required: [
      {
        required: true,
        message: '必填项',
        trigger: ['change', 'blur'],
      },
    ],

    // 手机号
    PhoneNum: [
      {
        required: true,
        message: '必填项',
        trigger: ['change', 'blur'],
      },
      {
        validator: (rule, value, callback) => {
          return uni.$u.test.mobile(value)
        },
        message: '无效手机号码',
        trigger: ['change', 'blur'],
      },
    ],
    // 身份证
    IdCard: [
      {
        required: true,
        message: '必填项',
        trigger: ['change', 'blur'],
      },
      {
        validator: (rule, value, callback) => {
          return uni.$u.test.idCard(value)
        },
        message: '无效身份证号',
        trigger: ['change', 'blur'],
      },
    ],
    // 不包含数字
    withoutNum: [
      {
        required: true,
        message: '必填项',
        trigger: ['change', 'blur'],
      },
      {
        validator: (rule, value, callback) => {
          return !/\d/.test(value)
        },
        message: '不能包含数字',
        trigger: ['change', 'blur'],
      },
    ],
  }

  if (rules[ruletype]) return rules[ruletype]

  return {
    type: 'string',
    required: true,
    message: '必填项',
    trigger: ['blur', 'change'],
  }
}

export const getDefault = ({ type, defaultval = null }) => {
  // console.log("getDefault:",defaultval)
  if (defaultval) return defaultval
  if (type == 'datetime') return Number(new Date())
  return ''
}
